//
//@File    :	14.20_tempmemb.cpp
//@Time    :	2022/02/24 10:22:16
//@Auther  :	Sun Sheng
//@Contact :	970340843@qq.com
//@Desc    :	template members
//

#include <iostream>
using std::cout;
using std::endl;

template <typename T>
class beta
{
private:
//模板类成员
    template<typename V>
    class hold
    {
    private:
        V val;
    public:
        hold(V v=0):val(v){}
        void show()const{cout<<val<<endl;}
        V Value() const{return val;}
    };


    hold<T> q;
    hold<int> n;

public:
    beta(T t,int i):q(t),n(i){}
//inline模板方法
//U类型由该方法被调用时的参数值显式确定
    template<typename U>
    U blab(U u,T t){return (n.Value()+q.Value())*u/t;}

    void Show() const{q.show();n.show();}
};

int main(){
    beta<double> guy(3.5,3);
    cout<<"Y was set to double\n";
    guy.Show();
    cout<<"V was set to T,which is double,then V was set to int\n";
    cout<<guy.blab(10,2.3)<<endl;
    cout<<"U was set to int\n";
    cout<<guy.blab(10.0,2.3)<<endl;
    cout<<"U was set to double\n";
    cout<<"Done\n";
    system("pause");
    return 0;
}